<% layout('/layouts/default.html', {title: '采购单管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('采购单管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<% if(hasPermi('st:stPurchaseBill:edit')){ %>
					<a href="${ctx}/st/stPurchaseBill/form" class="btn btn-default btnTool" title="${text('新增采购单')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<% } %>
				<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
<!--				<button id="sel">获取选中行</button>-->
				<script>
					$("#sel").click(function () {
						getSelectData();
					});
				</script>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${stPurchaseBill}" action="${ctx}/st/stPurchaseBill/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('单据号')}：</label>
					<div class="control-inline">
						<#form:input path="billNo" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('单据日期')}：</label>
					<div class="control-inline">
						<#form:input path="billDate" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('采购员编号')}：</label>
					<div class="control-inline">
						<#form:input path="buyerCode" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('采购员')}：</label>
					<div class="control-inline">
						<#form:input path="buyerName" maxlength="5" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('部门编码')}：</label>
					<div class="control-inline">
						<#form:input path="deptCode" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('部门')}：</label>
					<div class="control-inline">
						<#form:input path="deptName" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('供应商')}：</label>
					<div class="control-inline">
						<#form:input path="supplierId" maxlength="36" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('退/购货')}：</label>
					<div class="control-inline width-120">
						<#form:select path="inOrOut" dictType="st_purchase_in_or_out" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('币别')}：</label>
					<div class="control-inline width-120">
						<#form:select path="moneyType" dictType="st_money_type" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('合同编号')}：</label>
					<div class="control-inline">
						<#form:input path="contractNo" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('采购类别')}：</label>
					<div class="control-inline width-120">
						<#form:select path="buyType" dictType="st_buy_type" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('付款条件')}：</label>
					<div class="control-inline">
						<#form:input path="payWhere" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('交货方式')}：</label>
					<div class="control-inline width-120">
						<#form:select path="deliveryWay" dictType="st_delivery_way" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('审批状态')}：</label>
					<div class="control-inline width-120">
						<#form:select path="approveState" dictType="st_approve_state" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('审批人编码')}：</label>
					<div class="control-inline">
						<#form:input path="approveManCode" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('审批人')}：</label>
					<div class="control-inline">
						<#form:input path="approveManName" maxlength="5" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('备注信息')}：</label>
					<div class="control-inline">
						<#form:input path="remarks" maxlength="500" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
// 初始化DataGrid对象
var allData;
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text("单据号")}', name:'billNo', index:'a.bill_no', width:200, align:"left", frozen:true, formatter: function(val, obj, row, act){
			return val;
			// return '<a href="${ctx}/st/stPurchaseBill/form?id='+row.id+'" class="btnList" data-title="${text("编辑采购单")}">'+(val||row.id)+'</a>';
		}},
		{header:'${text("单据日期")}', name:'billDate', index:'a.bill_date', width:150, align:"center"},
		// {header:'${text("采购员编号")}', name:'buyerCode', index:'a.buyer_code', width:150, align:"left"},
		{header:'${text("采购员")}', name:'buyerName', index:'a.buyer_name', width:150, align:"left"},
		// {header:'${text("部门编码")}', name:'deptCode', index:'a.dept_code', width:150, align:"left"},
		{header:'${text("部门")}', name:'deptName', index:'a.dept_name', width:150, align:"left"},
		{header:'${text("供应商")}', name:'supplier.supplierFullName', index:'a.supplier_id', width:150, align:"left"},
		{header:'${text("退/购货")}', name:'inOrOut', index:'a.in_or_out', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('st_purchase_in_or_out')}, val, '${text("未知")}', true);
		}},
		{header:'${text("币别")}', name:'moneyType', index:'a.money_type', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('st_money_type')}, val, '${text("未知")}', true);
		}},
		{header:'${text("合同编号")}', name:'contractNo', index:'a.contract_no', width:150, align:"left"},
		{header:'${text("采购类别")}', name:'buyType', index:'a.buy_type', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('st_buy_type')}, val, '${text("未知")}', true);
		}},
		{header:'${text("付款条件")}', name:'payWhere', index:'a.pay_where', width:150, align:"left"},
		{header:'${text("交货方式")}', name:'deliveryWay', index:'a.delivery_way', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('st_delivery_way')}, val, '${text("未知")}', true);
		}},
		{header:'${text("审批状态")}', name:'approveState', index:'a.approve_state', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('st_approve_state')}, val, '${text("未知")}', true);
		}},
		{header:'${text("审批人编码")}', name:'approveManCode', index:'a.approve_man_code', width:150, align:"left"},
		{header:'${text("审批人")}', name:'approveManName', index:'a.approve_man_name', width:150, align:"left"},
		{header:'${text("更新时间")}', name:'updateDate', index:'a.update_date', width:150, align:"center"},
		{header:'${text("备注信息")}', name:'remarks', index:'a.remarks', width:150, align:"left"},
		{header:'${text("操作")}', name:'actions', width:120, sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [];
			<% if(hasPermi('st:stPurchaseBill:edit')){ %>
				actions.push('<a href="${ctx}/st/stPurchaseBill/form?id='+row.id+'" class="btnList" title="${text("编辑采购单")}"><i class="fa fa-pencil"></i></a>&nbsp;');
				actions.push('<a href="${ctx}/st/stPurchaseBill/delete?id='+row.id+'" class="btnList" title="${text("删除采购单")}" data-confirm="${text("确认要删除该采购单吗？")}"><i class="fa fa-trash-o"></i></a>&nbsp;');
			<% } %>
			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		// console.info("data", data);
		allData=data.list;
	}
});
function getSelectData(){
	var rowId=$('#dataGrid').dataGrid('getSelectRow');
	// var select=$('#dataGrid').dataGrid('getRowData', rowId);
	// select['id']=rowId;
	var select=null;
	for(var index in allData){

		var item=allData[index];
		if(item.id==rowId){
			select=item;
			break;
		}
	}
	return select;
}
</script>